package projectServlet;

import java.io.IOException;
import java.util.ArrayList;

//import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.DAOException;
import dao.LeaveDAOFactory;
import dao.mysql.LeaveDAOFactoryImpl;
import dto.LeaveDTO;
import dto.LeaveSearchDTO;
//import dto.UserDTO;

/**
 * Servlet implementation class Managerpage
 */
@WebServlet("/ManagerPagePreSet")
public class ManagerPagePreSet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ManagerPagePreSet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doprocess(request, response);		
	}


	private void doprocess(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		//int nm =3001;
		//HttpSession session = request.getSession();
		//LoginDTO login=(LoginDTO)session.getAttribute("USERSESSION");
		//int staffid=login.getStaffId();
	
		String SleaveID = request.getParameter("leaveDetailID");
		int LeaveID = Integer.parseInt(SleaveID.trim());
		
		LeaveDAOFactory LFactory = new LeaveDAOFactoryImpl();
				
		LeaveDTO Leave     = new LeaveDTO();
		
	try {
			Leave = LFactory.getLeaveDAO().findLeave(LeaveID);
			
		} catch (DAOException e) {;
			// TODO Auto-generated catch block 
			e.printStackTrace();
		}
		ArrayList<LeaveDTO> Leaveserchinfo = new ArrayList<LeaveDTO>();
		LeaveSearchDTO l2=new LeaveSearchDTO();
		//int userID = session.getAttribute("USERID");
		l2.set_ApprovingmanID(Leave.get_ApprovingManID());
		System.out.print(Leave.get_ApprovingManID());
		//l2.set_endDate(Leave.get_endDate());
		//l2.set_startDate(Leave.get_startDate());
		//l2.set_userID(Leave.get_userID());
		//l2.set_userName(Leave.get_userName());
		try {
			Leaveserchinfo=LFactory.getLeaveDAO().findSubordinatesOnLeave(l2);
			
		} catch (DAOException e) {;
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} 
		request.setAttribute("LeaveInfo", Leave);
		request.setAttribute("Leavesearchinfo", Leaveserchinfo);

		RequestDispatcher rd = request.getRequestDispatcher("ManagerViewDetail.jsp");
		rd.forward(request, response);
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doprocess(request, response);	// TODO Auto-generated method stub
	}

}